import { useState, useRef, MutableRefObject } from 'react'
import axios from 'axios'
import { useHistory } from 'react-router-dom'
// import { Button, Input } from 'antd';

const Login = () => {
  const [data, setData] = useState<any>({})
  const phone:any = useRef() // 一个useRef代表一个dom
  const password:any = useRef()
  const file:any = useRef()

  // useHistory凡是use开头的函数，都遵循所有的Hook 使用规则；
  // 先声明 后使用
  const history = useHistory()

  return <div>

      上传图片：<input type="file" ref={file} />


     <input type="text" ref={phone} /> <br/>
     <input type="text" ref={password}/> <br/>

     <button onClick={() => {
       axios.post('/api/login', {
         phone: phone.current.value.trim(),
         password: password.current.value.trim()
       }).then(res => {
         console.log('res:...:', res)
        //  if((res as any).errno == 0) {
           console.log('1....', res.data.data.token)
           // 同步操作
           localStorage.setItem('login-token', res.data.data.token)
           history.push('/home')
        //  }
       })
     }}>登陆</button>
  </div>
}

export default Login;
